//
//  MHLoginViewModel.m
//  MiaoCircle
//
//  Created by acgera on 2018/4/10.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHSetCirclePropertyViewModel.h"
#import "MHNetworking.h"
#import "MHWeChatAccessToken.h"
#import "MHHTTPService+Login.h"
#import "MHCircleInfo.h"
#import "MHSetCircleInfoViewModel.h"
#import "MHSetCirclePriceViewModel.h"
@interface MHSetCirclePropertyViewModel()
@property (nonatomic, readwrite, strong) RACCommand *nextCommand;
@property (nonatomic, readwrite, strong) RACCommand *closeCommand;

@end

NSString *const MHViewModelFinisedKey = @"MHViewModelTitleKey";
@implementation MHSetCirclePropertyViewModel


- (instancetype)initWithServices:(id<MHViewModelServices>)services params:(NSDictionary *)params{
    if (self = [super initWithServices:services params:params]) {
        MHCircleInfo *info =  [MHCircleInfo new];
        info.category = MHCirclContenTypeText;
        info.payType = MHCirclPayTypeUnkown;
        self.info = params[MHViewModelUtilKey]?:info;
        self.title = @"选择付款模式";
//        self.backTitle = params[MHViewModelUtilKey]?@"":@"取消";
        self.isFinished =  true ;//params[MHViewModelIsFinisedKey];
        
    }
    return self;
}


- (void)initialize
{
    [super initialize];
    @weakify(self);
    self.nextCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
        @strongify(self);
        if (self.info && self.isFinished) {
            if (self.info.payType == MHCirclPayTypeCharge) {
                MHSetCirclePriceViewModel *viewModel = [[MHSetCirclePriceViewModel alloc] initWithServices:self.services params:@{MHViewModelUtilKey: self.info}];
                            [self.services pushViewModel:viewModel animated:YES];
            }else
            {
                MHSetCircleInfoViewModel *viewModel = [[MHSetCircleInfoViewModel alloc] initWithServices:self.services params:@{MHViewModelUtilKey:self.info, MHViewModelIsCreate :@(true)}];
                [self.services pushViewModel:viewModel animated:YES];
            }
            
        }else
        {
            MHSetCirclePropertyViewModel *viewModel = [[MHSetCirclePropertyViewModel alloc] initWithServices:self.services params:@{MHViewModelUtilKey:self.info,MHViewModelIsFinisedKey:@true}];
            [self.services pushViewModel:viewModel animated:YES];
           
        }
         return [RACSignal empty];
    }];
    
    self.callback = ^(id call) {
      
    };
    
    self.closeCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
        @strongify(self);
        [self.services popViewModelAnimated:YES];
        return [RACSignal empty];
    }];
    
}


@end
